<template>
  <div class="header-nav ">
    <div class="logo">
      <img src="@/assets/home/header/platform.png" alt="AI智慧学习中心" />
    </div>
    <div class="nav-items">
      <div v-for="(item, index) in navItems" :key="index" class="nav-item" :class="{ active: activeIndex === index }"
        @click="handleNavClick(index)">
        <span class="nav-item-txt">{{ item.name }}</span>
      </div>
    </div>
    <div class="user-avatar" @click="gotoUserCenter">
      <img src="@/assets/home/header/favicon.ico" alt="" />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router'; // 
import { getActivityAll } from "@/api/system/activity";

const router = useRouter();
const activeIndex = ref(-1);

const navItems = ref([]);

function gotoUserCenter() {
  router.push({ name: 'Profile' });
}

function getNavis() {
  getActivityAll().then(res => {
    if (res.code == 200) {
      const resData = res.data;

      // 根据name和title匹配并合并数据
      navItems.value = resData.map(item => {
        return {
          name: item.title,
          typeId: item.bannerType,
        };
      });

      console.log('navItems:', navItems.value);
    }
  });
}
getNavis();

const handleNavClick = (index) => {
  activeIndex.value = index;
  // 路由跳转时添加typeId参数
  router.push({
    name: 'HomeIndex',
    query: {
      typeId: navItems.value[index].typeId
    }
  });
};
</script>

<style scoped>
@font-face {
  font-family: 'YanShiQiuHongKai-2';
  src: url('@/assets/font/YanShiQiuHongKai-2.ttf') format('truetype');
}

.header-nav {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 8%;
  min-height: 120px;
  background-image: url('@/assets/home/bg-show.png');
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

/* 顶部导航栏 */
.header-nav::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 120px;
  z-index: 1;
}

/* 添加波浪背景效果 */
.header-nav::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: bottom;
  z-index: 0;
  opacity: 0.7;
}

.logo {
  position: absolute;
  top: 10px;
  left: 20px;
  z-index: 2;
}

.logo img {
  height: 100px;
}

.nav-items {
  position: absolute;
  top: 30px;
  left: 53%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  z-index: 2;
}

.nav-item {
  cursor: pointer;
  padding: 10px 10px;
  border-radius: 20px;
  width: 160px;
  height: 80px;
  margin-bottom: 10px;
  transition: all 0.3s ease;
  background-image: url('@/assets/home/header/navi-item.png');
  background-size: 95% 90%;
  background-position-y: 6px;
  background-repeat: no-repeat;
}

.nav-item .nav-item-txt {
  position: relative;
  top: 8px;
  left: 30px;
  font-size: 28px;
  font-weight: bold;
  color: #4487FF;

  align-items: center;
  height: 80px;
  font-family: 'YanShiQiuHongKai-2', 'Microsoft YaHei';
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.8),
    0 0 10px rgba(255, 255, 255, 0.6),
    0 0 15px rgba(255, 255, 255, 0.4);
}



.nav-item.active {
  background-color: rgba(255, 255, 255, 0.3);
}

.user-avatar {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2;
  cursor: pointer;
}

.user-avatar img {
  width: 80px;
  height: 80px;
  border-radius: 50%;

}

/* 适配低分屏 */
/* @media (min-height: 769px) {
  .header-nav {
    min-height: 110px;
  }

  .logo {
    left: 8px;
  }

  .logo img {
    height: 88px;
  }

  .user-avatar {
    top: 10px;
    right: 10px;
  }

  .user-avatar img {
    width: 83px;
    height: 80px;
  }

  .nav-items {
    left: 26%;
    top: 18px;
    gap: 4px;
    transform: none;
  }

  .nav-item {
    width: 150px;
    height: 80px;
    padding: 8px 24px;
    background-size: 90% 80%;
  }

  .nav-item .nav-item-txt {
    font-size: 24px;
    left: 12px;
    height: 50px;
  }
} */
/* 适配低分屏 */
@media (max-width: 1655px) {
  .header-nav {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 3%;
    min-height: 90px;
    background-image: url('@/assets/home/bg-show.png');
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
  }

  .logo {
    left: 8px;
  }

  .logo img {
    height: 78px;
  }

  .user-avatar {
    top: 10px;
    right: 10px;
  }

  .user-avatar img {
    width: 76px;
    height: 76px;
  }

  .nav-items {
    left: 26%;
    top: 18px;
    gap: 4px;
    transform: none;
  }

  .nav-item {
    width: 120px;
    height: 70px;
    padding: 8px 14px;
    background-size: 90% 80%;
  }

  .nav-item .nav-item-txt {
    font-size: 19px;
    left: 12px;
    height: 40px;
  }
}
</style>